<template>
  <div class="app-container">

    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="searchObj.hosname" placeholder="医院名称"/>
      </el-form-item>
      <el-form-item>
        <el-input v-model="searchObj.patientName" placeholder="就诊人名称"/>
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="fetchData()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>

    <!-- 列表 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      stripe
      style="width: 100%">

      <el-table-column
        label="序号"
        width="70"
        align="center" fixed>
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

<!--      <el-table-column prop="userId" label="信息认证人id"/>-->
      <el-table-column prop="outTradeNo" label="订单交易号" width="150"/>
      <el-table-column prop="hosname" label="医院名称" width="150"/>
      <el-table-column prop="depname" label="科室名称" width="180"/>
      <el-table-column prop="title" label="医生职称" width="100"/>
      <el-table-column prop="reserveDate" label="安排日期" width="100"/>


      <el-table-column label="安排时间">
        <template slot-scope="scope">
          <span v-if="scope.row.reserveTime===0">上午</span>
          <span v-if="scope.row.reserveTime===1">下午</span>
        </template>
      </el-table-column>
      <el-table-column prop="patientName" label="就诊人姓名" width="100"/>
      <el-table-column prop="patientPhone" label="就诊人手机" width="150"/>
      <el-table-column prop="number" label="预约号序"/>
      <el-table-column prop="fetchAddress" label="取号地点" width="150"/>
      <el-table-column prop="amount" label="挂号费用"/>
      <el-table-column prop="quitTime" label="退号时间"/>
      <el-table-column label="订单状态" >
        <template slot-scope="scope">
          <span v-if="scope.row.orderStatus===0" style="color: red">未支付</span>
          <span v-if="scope.row.orderStatus===1">已支付</span>
        </template>
      </el-table-column>


      <el-table-column label="操作" width="140" align="center"  fixed="right" >
        <template slot-scope="scope">
          <router-link :to="'/order/orderInfo'" v-if="scope.row.orderStatus===0">
            <el-button type="primary" size="mini"  disabled>查看支付信息</el-button>
          </router-link>
          <router-link :to="'/order/paymentInfo/'+scope.row.id" v-if="scope.row.orderStatus===1">
            <el-button type="primary" size="mini" >查看支付信息</el-button>
          </router-link>

          <router-link :to="'/order/orderInfo'" v-if="scope.row.orderStatus===0">
            <el-button type="info" size="mini"  disabled>查看退款信息</el-button>
          </router-link>
          <router-link :to="'/order/refundInfo/'+scope.row.id" v-if="scope.row.orderStatus===1">
            <el-button type="info" size="mini" >查看退款信息</el-button>
          </router-link>
        </template>
      </el-table-column>

    </el-table>

    <!-- 分页组件 -->
    <el-pagination
      :current-page="page"
      :total="total"
      :page-size="limit"
      :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
      style="padding: 30px 0; text-align: center;"
      layout="sizes, prev, pager, next, jumper, ->, total, slot"
      @current-change="fetchData"
      @size-change="changeSize"
    />
  </div>
</template>
<script>
import orderInfoApi from '@/api/order/orderInfo'

export default {

  // 定义数据
  data() {
    return {
      listLoading: true, // 数据是否正在加载
      list: [{
        orderInfo: {},
        userInfo: {
          name: "爸爸"
        }
      }], // banner列表

      total: 0, // 数据库中的总记录数
      page: 1, // 默认页码
      limit: 5, // 每页记录数
      searchObj: {
        hosname:"",
        patientName:""
      }, // 查询表单对象
      status: null


    }
  },

  // 当页面加载时获取数据
  created() {
     this.fetchData()
  },

  methods: {
    // 调用api层获取数据库中的数据
    fetchData(page = 1) {
      console.log('翻页。。。' + page)
      // 异步获取远程数据（ajax）
      this.page = page
      console.log("searchObj",this.searchObj)
      orderInfoApi.queryAllAndPage(this.page, this.limit, this.searchObj).then(
        response => {
          //订单数据
          console.log("返回数据",response.data)
          this.list = response.data.records
          this.total = response.data.total

          // 数据加载并绑定成功
          this.listLoading = false
        }
      )
    },

    // 当页码发生改变的时候
    changeSize(size) {
      console.log(size)
      this.limit = size
      this.fetchData(1)
    },

    // 重置查询表单
    resetData() {
      console.log('重置查询表单')
      this.searchObj = {}
      this.fetchData()
    }

  }
}
</script>
